package com.ww.www;

import java.net.MalformedURLException;
import java.util.List;

import org.openqa.selenium.By;
import org.testng.annotations.Test;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import utils.BaseAction;

public class XX extends BaseTest{
	private AndroidDriver<AndroidElement> driver;
	private BaseAction action;

	public void Page01(AndroidDriver<AndroidElement> driver) {
		this.driver = driver;
		this.action = new BaseAction(driver);
	}
//获取定位元素-聊天按钮
	public AndroidElement get_chat() {
		return driver.findElementByXPath("//*[@content-desc=\"聊天 聊天 第 1 个标签，共 3 个\"]");
	}
	//获取定位元素-通讯录按钮
	public AndroidElement get_list() {
		return driver.findElementByXPath("[@content-desc=\"通讯录 通讯录 第 2 个标签，共 3 个\"]");
	}
	//获取定位元素-我的按钮
	public AndroidElement get_mine() {
		return driver.findElementByXPath("[@content-desc=\"我的 我的 第 3 个标签，共 3 个\"]");
	}
	//获取定位元素-创建聊天按钮
	public AndroidElement add_chat() {
		return driver.findElementByXPath("[@content-desc=\"创建聊天\"]");
	}
	//获取定位元素-聊天界面输入框
	public AndroidElement chat_test() {
		return driver.findElementByXPath("[@content-desc=\"搜索\"]");
	}
    
	//获取定位元素-聊天界面edittext输入-关键字
	public AndroidElement chat_put2() {
		return driver.findElementByClassName("android.widget.EditText");
	}
	
	//获取定位元素-聊天界面输入框
	public AndroidElement chat_cancel() {
		return driver.findElementByXPath("[@content-desc=\"取消\"]");
	}	
	//获取定位元素-对话框输入框
	public AndroidElement chat_edit() {
		return driver.findElementByXPath("//*[@text='发送消息']");
	}	
	//获取定位元素-对话框发送按钮
	public AndroidElement chat_send() {
		return driver.findElementByClassName("android.widget.Button");
	}	
	
    //获取 聊天界面-第一个对话框
	public AndroidElement list_item0() {
		AndroidElement list_view = (AndroidElement) driver.findElementById("android:id/list");
		List<MobileElement> items = list_view.findElements(By.className("android.widget.TextView"));
		return (AndroidElement) items.get(0);
	}
	//获取定位元素-对话框 显示菜单
	public AndroidElement chat_menu() {
		return driver.findElementByXPath("[@content-desc=\"显示菜单\"]");
	}	
	
	//获取定位元素-对话框 显示菜单-成员列表
	public AndroidElement menu_people() {
		return driver.findElementByXPath("[@content-desc=\"成员列表\"]");
	}	
	//获取定位元素-对话框 显示菜单-重命名
	public AndroidElement menu_rename() {
		return driver.findElementByXPath("[@content-desc=\"重命名\"]");
	}	
	//获取定位元素-对话框 显示菜单-重命名会话-编辑 android.widget.EditText
	public AndroidElement rename_edit() {
		return driver.findElementByClassName("android.widget.EditText");
	}	
	//获取定位元素-对话框 显示菜单-重命名会话-取消
	public AndroidElement rename_cancel() {
		return driver.findElementByXPath("//*[@index='1']");
	}
	//获取定位元素-对话框 显示菜单-重命名会话-确定
	public AndroidElement rename() {
		return driver.findElementByXPath("//*[@index='2']");
	}	
	//获取定位元素-对话框 聊天内容
	public AndroidElement content01() {
		return driver.findElementByXPath("//*(//android.view.View[@content-desc=\"123\"])[2]");
	}	
	
	

	//点击聊天-输入框-进入输入界面-输入用户名查询
	@Test(priority = 1)
	public void  test01(String message) throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.chat_test());
	
		action.type(this.chat_put2(),message);
		
	}
	//点击聊天-输入框-进入输入界面-取消
	@Test(priority = 2)
	public void  test02(String message) throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.chat_test());
	
		action.type(this.chat_put2(),message);
		action.click(this.chat_cancel());
		
	}
	//点击聊天-获取第一个对话框-输入文本-发送
	@Test(priority = 3)
	public void  test03(String message) throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
	
		action.type(this.chat_edit(),message);
		action.click(this.chat_send());
		
	}
	//点击聊天-获取第一个对话框-点击右上角-显示成员列表
	@Test(priority = 4)
	public void  test04() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
	
		action.click(this.chat_menu());
		action.click(this.menu_people());
		
	}
	//点击聊天-获取第一个对话框-点击右上角-重命名
	@Test(priority = 5)
	public void  test05(String message) throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
	
		action.click(this.chat_menu());
		action.click(this.menu_rename());
		
	}
	//点击聊天-获取第一个对话框-点击右上角-重命名编辑-取消
	@Test(priority = 6)
	public void  test06(String message) throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		action.click(this.chat_menu());
		action.click(this.menu_rename());
		action.type(this.rename_edit(),message);
		action.click(this.rename_cancel());
		
	}
	//点击聊天-获取第一个对话框-点击右上角-直接取消
	@Test(priority = 7)
	public void  test07() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		action.click(this.chat_menu());
		action.click(this.menu_rename());
		action.click(this.rename_cancel());
		
	}
	//点击聊天-获取第一个对话框-点击右上角-重命名编辑-确定
	@Test(priority = 8)
	public void  test08(String message) throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		action.click(this.chat_menu());
		action.click(this.menu_rename());
		action.type(this.rename_edit(),message);
		action.click(this.rename());
	}
	//点击聊天-聊天内容长按 复制粘贴再发送
	@Test(priority = 9)
	public void  test09() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		this.longPress(content01());
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"复制\"]").click();
		Thread.sleep(3000);
		this.longPress(chat_edit());
		Thread.sleep(3000);
		action.click(this.chat_send());
		
	}
	//点击聊天-长按聊天内容 点击转发 选择用户
	@Test(priority = 10)
	public void  test10() throws MalformedURLException, InterruptedException {
		action.click(this.get_chat());
		action.click(this.list_item0());
		this.longPress(content01());
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"转发\"]").click();
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"Z zw01\"]").click();
	}
	//点击聊天-长按聊天内容 点击分享 选择方式 转发给用户
	@Test(priority = 11)
	public void  test11() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		this.longPress(content01());
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"分享...\"]").click();
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"分享...\"]").click();
		driver.findElementByXPath("//*[@text='喧喧']").click();
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"Z zw01\"]").click();
		
	}
	//点击聊天-聊天界面 点击用户头像-进入个人主页
	@Test(priority = 12)
	public void  test12() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		
		driver.findElementByXPath("(//android.view.View[@content-desc=\"A\"])[3]").click();
		Thread.sleep(3000);
		
	}
	
	//点击聊天-聊天界面 点击+  -点击相机
	@Test(priority = 13)
	public void  test13() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		
		driver.findElementByXPath("//android.widget.Button[@content-desc=\"发送其他内容\"]").click();
		
		Thread.sleep(3000);
		
		//android.view.View[@content-desc="拍照"]
        driver.findElementByXPath("//android.view.View[@content-desc=\"拍照\"]").click();
		
		Thread.sleep(3000);
		
		
	}
	//点击聊天-聊天界面 点击+  -点击相册
	@Test(priority = 14)
	public void  test14() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		
		driver.findElementByXPath("(//android.view.View[@content-desc=\"A\"])[3]").click();
		Thread.sleep(3000);		action.click(this.get_chat());
		action.click(this.list_item0());
		
		driver.findElementByXPath("//android.widget.Button[@content-desc=\"发送其他内容\"]").click();
		
		Thread.sleep(3000);
	
        driver.findElementByXPath("//android.view.View[@content-desc=\"照片\"]").click();
		
		Thread.sleep(3000);
		
		
	}
	//点击聊天-聊天界面 点击+  -点击文件
	@Test(priority = 15)
	public void  test15() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_chat());
		action.click(this.list_item0());
		
		driver.findElementByXPath("//android.widget.Button[@content-desc=\"发送其他内容\"]").click();
		
		Thread.sleep(3000);
	
        driver.findElementByXPath("//android.view.View[@content-desc=\"文件\"]").click();
		
		Thread.sleep(3000);
		
		
	}
	//通讯录-点击第二个用户 进入主页
	@Test(priority = 16)
	public void  test16() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_list());
		
		
		driver.findElementByXPath("//android.view.View[@content-desc=\"Z zw01\"]").click();
		Thread.sleep(3000);
		
	}
	///通讯录-点击第二个用户 进入主页-收藏
	@Test(priority = 17)
	public void  test17() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_list());
		
		
		driver.findElementByXPath("//android.view.View[@content-desc=\"Z zw01\"]").click();
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"取消收藏\"]").click();
		Thread.sleep(3000);
		
		
	}
	//通讯录-点击第二个用户 进入主页-聊天按钮
	@Test(priority = 18)
	public void  test18() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_list());
		
		
		driver.findElementByXPath("//android.view.View[@content-desc=\"Z zw01\"]").click();
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"开聊\"]").click();
		Thread.sleep(3000);
		
		
	}
	//通讯录-点击第二个用户 进入主页-收藏-取消收藏
	@Test(priority = 19)
	public void  test19() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_list());
		
		
		driver.findElementByXPath("//android.view.View[@content-desc=\"Z zw01\"]").click();
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"取消收藏\"]").click();
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"取消收藏\"]").click();
		Thread.sleep(3000);
		
	}
	//通讯录-点击第二个用户 进入主页-点击 返回
	@Test(priority = 20)
	public void  test20() throws MalformedURLException, InterruptedException {
		
		action.click(this.get_list());
		
		
		driver.findElementByXPath("//android.view.View[@content-desc=\"Z zw01\"]").click();
		Thread.sleep(3000);
		driver.findElementByXPath("//android.view.View[@content-desc=\"返回\"]").click();
		Thread.sleep(3000);
		
	}

}